<?php

namespace app\admin\model;

use think\Db;
use think\Model;
use think\Request;
use think\Exception;


class User extends Model
{
    // 设置当前模型对应的完整数据表名称
//    protected $table = 'gwd_user';

    public function index($name)
    {
//        // 返回值为对象
//        $obj = Self::all(function ($query) {
//            $query->where('status', 'neq', 3)->paginate(3,true);
//        });

//        return $obj;

            $list = Self::where('status', 'neq', 3)->where('nickname', 'like', $name)->paginate(2, false, [
                'query' => Request::instance()->param(),//不丢失已存在的url参数
            ]);

        return $list;
    }

    public function doadd($data)
    {
        try {
            $res = $this->data($data)->allowField(true)->save();
            return $res;
        } catch (exception $e) {

            return false;
        }
    }

    public function doedit($data)
    {
        $res = $this->isUpdate()->save($data);
        return $res;
    }

    public function read($id)
    {
//        $obj = Self::get($id);
//        return $obj;
        $info = Db::name('user')->field('pass', true)->find($id);

        return $info;
    }

}
